package com.example.babyapp;

import java.util.Calendar;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

public class InfoActivity extends Activity{
	
	Button btn;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_info);
        setOrientation();
        
        Button dateBtn = (Button) findViewById(R.id.datebtn);
        
        final OnDateSetListener odsl=new OnDateSetListener(){
            public void onDateSet(DatePicker arg0, int year, int month, int dayOfMonth) {
             // TODO Auto-generated method stub
         	   String fMonth = null;
         	   switch(month){
         	   case 0: fMonth = "Jan";
         	   			break;
         	   case 1: fMonth = "Feb";
 	   					break;
         	   case 2: fMonth = "Mar";
 	   					break;
         	   case 3: fMonth = "Apr";
 	   					break;
         	   case 4: fMonth = "May";
 	   					break;
         	   case 5: fMonth = "Jun";
 	   					break;
         	   case 6: fMonth = "Jul";
 	   					break;
         	   case 7: fMonth = "Aug";
 	   					break;
         	   case 8: fMonth = "Sep";
 	   					break;
         	   case 9: fMonth = "Oct";
 	   					break;
         	   case 10: fMonth = "Nov";
 	   					break;
         	   case 11: fMonth = "Dec";
 	   					break;
         	   }
         	   
             TextView txt=(TextView)findViewById(R.id.bdayField);
             txt.setText(dayOfMonth+" "+fMonth+" "+year);
            }};

         dateBtn.setOnClickListener(new OnClickListener() {
            public void onClick(View arg0) {
             // TODO Auto-generated method stub
             Calendar cal=Calendar.getInstance();
             DatePickerDialog datePickDiag=new DatePickerDialog(InfoActivity.this,odsl,cal.get(Calendar.YEAR),cal.get(Calendar.MONTH),cal.get(Calendar.DAY_OF_MONTH));
             datePickDiag.show();
            }});
    }
	
	public void gotoSecondInfoActivity(View view) {
		Intent intent = new Intent(this, SecondInfoActivity.class);
		
		EditText lastName = (EditText) findViewById(R.id.lastnameField);
		EditText firstName = (EditText) findViewById(R.id.firstnameField);
		RadioButton fGender = (RadioButton) findViewById(R.id.radio0);
		RadioButton mGender = (RadioButton) findViewById(R.id.radio1);
		EditText birthDay = (EditText) findViewById(R.id.bdayField);
		EditText placeOfBirth = (EditText) findViewById(R.id.pobField);
		EditText birthWeight = (EditText) findViewById(R.id.bweightField);
		
		String strGender = null;
		if (fGender.isChecked() == true) {
			strGender = "Female";
		} else if (mGender.isChecked() == true) {
			strGender = "Male";
		}
		
		if (lastName == null || firstName == null || strGender == null || birthDay == null || placeOfBirth == null || birthWeight == null){
			Toast.makeText(getApplicationContext(), "Please fill up all fields.", Toast.LENGTH_SHORT).show();
		} else if (lastName != null && firstName != null && strGender != null && birthDay != null && placeOfBirth != null && birthWeight != null){
		
		String[] babyInfo = { lastName.getText().toString(), firstName.getText().toString(), strGender, birthDay.getText().toString(),
							placeOfBirth.getText().toString(), birthWeight.getText().toString() };
		
		intent.putExtra("babyInfo", babyInfo);
		startActivity(intent);
		}
	}
	
	protected void setOrientation() {
    	int current = getRequestedOrientation();
    	if(current != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT){
    		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    	}
    }

}
